//
//  ProgramTableViewCell.m
//  MountEverestFM
//
//  Created by ChenNing on 15/11/5.
//  Copyright © 2015年 chenn. All rights reserved.
//

#import "ProgramTableViewCell.h"

@interface ProgramTableViewCell()
// 排名
@property(nonatomic,strong)UILabel *indexLabel;
// 头像
@property(nonatomic,strong)UIImageView *topImageView;
// 昵称
@property(nonatomic,strong)UILabel *nickNameLabel;
// say
@property(nonatomic,strong)UILabel *contentLabel;
@end

@implementation ProgramTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.indexLabel = [[UILabel alloc] init];
        self.indexLabel.font = [UIFont systemFontOfSize:15];
        self.indexLabel.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:_indexLabel];
        
        self.topImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_topImageView];
        
        self.nickNameLabel = [[UILabel alloc] init];
        self.nickNameLabel.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:_nickNameLabel];
        
        self.contentLabel = [[UILabel alloc] init];
        self.contentLabel.font = [UIFont systemFontOfSize:13];
        self.contentLabel.textColor = [UIColor grayColor];
        self.contentLabel.numberOfLines = 0;
        [self.contentLabel sizeToFit];
        [self.contentView addSubview:_contentLabel];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];

}

- (void)setTopDic:(NSDictionary *)topDic
{
    if (_topDic != topDic) {
        _topDic = topDic;
    }
    [self setTopInfo:topDic];
}

- (void)setIndex:(NSInteger)index
{
    if (_index != index) {
        _index = index;
    }
}

- (void)setTopInfo:(NSDictionary *)topDic
{
    // 序号
    self.indexLabel.frame = CGRectMake(FM_Screen_Pts_Width*10, 0, FM_Screen_Pts_Width*25, self.contentView.bounds.size.height);
    self.indexLabel.text = [NSString stringWithFormat:@"%ld",self.index];
    
    // 头像
    self.topImageView.frame = CGRectMake(FM_Screen_Pts_Width*40, FM_Screen_Pts_Height*10, FM_Screen_Pts_Width*70, FM_Screen_Pts_Width*70);
    NSString *imageUrl = [topDic objectForKey:@"middleLogo"];
    [self.topImageView sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:[UIImage imageNamed:@"find_kind_btn_default@3x.png"]];
    
    // 昵称
    self.nickNameLabel.text = [topDic objectForKey:@"nickname"];
    self.nickNameLabel.frame = CGRectMake(FM_Screen_Pts_Width*120, FM_Screen_Pts_Height*10, FM_Screen_Width-FM_Screen_Pts_Width*130, FM_Screen_Pts_Width*20);

    // say
    NSString *personDescribe = [topDic objectForKey:@"personDescribe"];
    CGRect contentRect = [personDescribe boundingRectWithSize:CGSizeMake(FM_Screen_Width-FM_Screen_Pts_Width*130, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13]} context:nil];
    // say
    CGFloat contentHeight = 0;
    if (contentRect.size.height > self.topImageView.frame.size.height/2) {
        contentHeight = self.topImageView.frame.size.height/2;
    }else{
        contentHeight = contentRect.size.height;
    }
    self.contentLabel.frame = CGRectMake(FM_Screen_Pts_Width*120, FM_Screen_Pts_Height*10+FM_Screen_Pts_Width*70- contentHeight, FM_Screen_Width-FM_Screen_Pts_Width*130, contentHeight);
    self.contentLabel.text = personDescribe;
}

@end
